/**
 * Projet Multicast Bidois Morgan & Thomas Nunes
 *
 */
package Engine;

import static Engine.TypeMessage.*;

/**
 * The flag is a part of a message indicated his type
 *
 * @author thomas
 */
public class Header {

    private TypeMessage type;
    private int logicalClock;
    private int idClient;

    public Header(TypeMessage typeMessage, int clock, int idClient) {
        this.type = typeMessage;
        this.logicalClock = clock;
        this.idClient = idClient;

    }

    public Header(short indice, int clock, int idClient) {
        this.logicalClock = clock;
        this.idClient = idClient;
        switch (indice) {
            case 0:
                this.type = TypeMessage.DIE;
                break;
            case 1:
                this.type = TypeMessage.NORMAL;
                break;
            case 6:
                this.type = TypeMessage.NEW_CONNECTION;
                break;
            case 2:
                this.type = TypeMessage.SOMEONE_LEAVE;
                break;
            case 3:
                this.type = TypeMessage.START_BURST;
                break;
            case 4:
                this.type = TypeMessage.STOP_BURST;
                break;
            case 5:
                this.type = TypeMessage.ACK;
                break;
            case 7:
                this.type = TypeMessage.SEND_DIRECTORY;
                break;
            case 8:
                this.type = TypeMessage.SEND_ID;
                break;
            case 9:
                this.type = TypeMessage.CLIENT_SERVERSOCKET_READY;
                break;
            case 10:
                this.type = TypeMessage.BEGIN_CONNECTION;
                break;
            case 11:
                this.type = TypeMessage.GIVE_ME_A_MESSAGE;
                break;
            case 12:
                this.type = TypeMessage.WELCOME;
                break;
            case 13:
                this.type = TypeMessage.TAKE_MY_HISTORIC;
                break;
            default:
                this.type = TypeMessage.UNKNOWN;
        }
    }

    public TypeMessage getType() {
        return type;
    }

    public void setType(TypeMessage type) {
        this.type = type;
    }

    @Override
    public String toString() {
        return this.getType().toString();
    }

    public int getLogicalClock() {
        return logicalClock;
    }

    public void setLogicalClock(int logicalClock) {
        this.logicalClock = logicalClock;
    }

    public int getIdClient() {
        return idClient;
    }

    public void setIdClient(int idClient) {
        this.idClient = idClient;
    }

    /**
     * get the number corresponding to the type of flag
     *
     * @return the number coresponding to the flag
     */
    public short getShort() {
        switch (type) {
            case DIE:
                return 0;
            case NORMAL:
                return 1;
            case SOMEONE_LEAVE:
                return 2;
            case START_BURST:
                return 3;
            case STOP_BURST:
                return 4;
            case ACK:
                return 5;
            case NEW_CONNECTION:
                return 6;
            case SEND_DIRECTORY:
                return 7;
            case SEND_ID:
                return 8;
            case CLIENT_SERVERSOCKET_READY:
                return 9;
            case BEGIN_CONNECTION:
                return 10;
            case GIVE_ME_A_MESSAGE:
                return 11;
            case WELCOME:
                return 12;
            case TAKE_MY_HISTORIC:
                return 13;
        }
        return 0;
    }
}
